package com.xzg.erp.process.web;

import com.xzg.erp.common.Constants;
import com.xzg.erp.process.service.MyProcessService;
import org.flowable.task.api.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/process")
public class MyProcessController {

    @Autowired
    private MyProcessService myProcessService;

    @PostMapping("/start")
    public String get() {
        myProcessService.startProcess();
        return "ok";
    }

    @GetMapping("/page/definitions")
    public ResponseEntity pageDefinitions() {
        return ResponseEntity.ok(myProcessService.pageDefinitions());
    }

    @GetMapping("/groups/definitions")
    public ResponseEntity groupsDefinitions() {
        return ResponseEntity.ok(myProcessService.groupsDefinitions());
    }

    @GetMapping("/definition/image/{processDefinitionId}")
    public ResponseEntity taskImage(@PathVariable String processDefinitionId) {
        return ResponseEntity.ok(myProcessService.definitionImage(processDefinitionId));
    }


    static class TaskRepresentation {

        private String id;
        private String name;

        public TaskRepresentation(String id, String name) {
            this.id = id;
            this.name = name;
        }

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

    }
}
